<?php
/*
 * 第三方班级信息控制器
 */
class ClassController extends BasicController {
    
    private function init(){
        Yaf_Registry::get('tokenPlugin')->checkOtherAuth();
    }

    /*
    * 人机英语 - 根据班级id获取班级学生列表 Api
    */
    public function studentlistAction(){
        $params = $this->getPost();
        
        $class_id = isset($params['class_id']) ? $params['class_id'] : 0;
        
        $return['code'] = "0";
        $return['msg'] = '操作成功！';
        $return['data'] = [];
        
        if(!$class_id){
            $return['code'] = "1";
            $return['msg'] = '参数错误';
            
            echo json_encode($return);
            return false;
        }
        
        $UserDetailModel = Helper::load('User_detail');
        
        $list = $UserDetailModel->Where(['class_id' => $class_id, 'isdelete' => 0])->Select();
        
        $data = [];
        if(!empty($list) && is_array($list)){//找不到 / 无效
            foreach($list as $item){
                $data[] = [
                    'id'    => $item['user_id'],
                    'name'  => $item['user_realname']
                ];
            }
        }
        
        $return['data'] = $data;
        
        echo json_encode($return);
        return false;
    }
    
    
}